<?php

namespace app\index\model;

use think\Model;
use think\Db;
class Auser extends Model
{


    protected $name = 'a_user';


    public function shu()
    {


        return $this->hasOne('Shu', 'user_id');
    }


    public function di(){


 $data=Auser::with('shu')->select();

 return $data;
    }
    public function ce()
    {


// 启动事务
        Db::startTrans();
        try {


            $this->allowField(true)->save([

                'nane' => 'guiqi',
                'age' => 21,


            ]);

$this->shu()->save([

'shuname'=>'三国演义',
    'jiage'=>33,


]);
            // 提交事务
            print_r('成功了');
            Db::commit();
        } catch (\Exception $e) {
            // 回滚事务
            print_r('失败了');
            Db::rollback();
        }


    }

}
